package com.example.orderserver.service;

import com.example.orderserver.dao.OrderDetailetDao;
import com.example.orderserver.entities.OrderDetailet;
import com.example.server_engineer.service.AbstractTypedService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 */
@Slf4j
@Service
public class OrderDetailetService
        extends AbstractTypedService<OrderDetailet, Integer> {

    OrderDetailetDao orderDetailetDao;

    OrderDetailetService(OrderDetailetDao dao) {
        this.dataContext = dao;
        this.orderDetailetDao = dao;
    }

    public List<OrderDetailet> queryAll() {
        List<OrderDetailet> lst = null;
        try {
            lst = ((OrderDetailetDao) this.dataContext).findAll();
            log.info("find orderDetailet: " + lst.size());
        } catch (Exception e) {
            log.warn(e.toString());
        }

        return lst;
    }

    // 根据orderid查询orderdetailet
    // 根据orderid查订单明细
    public List<OrderDetailet> queryByOrderid(Integer orderid){
        return orderDetailetDao.findOrderDetailetByOrderId(orderid);
    }

    public Page<OrderDetailet> queryOrderByPage(Pageable pageable) {
        return orderDetailetDao.queryPage(pageable, null);
    }
}
